import asyncio
import re
import time
import urllib
from itertools import zip_longest
import ctypes
from urllib import request
from pyppeteer import launch
async def scroll_to_bottom(page):
    await page.evaluate('''() => {  
        window.scrollTo(0, document.body.scrollHeight);  
    }''')


async def main():
    # 启动浏览器
    browser = await launch(executablePath='C:\Program Files\Google\Chrome\Application\chrome.exe',headless=False)
    # 新建一个页面
    page = await browser.newPage()
    try:
        user32 = ctypes.windll.user32
        screen_width = user32.GetSystemMetrics(0)
        screen_height = user32.GetSystemMetrics(1)

    except ImportError:
        screen_width = 1920
        screen_height = 1080

    # 设置视口大小以模拟最大化窗口
    await page.setViewport({'width': screen_width, 'height': screen_height})
    # 设置请求头
    # await page.setCookie(cookies)
    # await page.setExtraHTTPHeaders(headers=headers)
    # 访问指定网址
    url='https://login.1688.com/member/signin.htm'
    await page.goto(url,timeout=600000000000)
    # 获取页面数据
    await scroll_to_bottom(page)
    time.sleep(10)
    content = await page.content()
    print(content)
    pattern_name = r',"tpCreditUrl":"http://(.*?).1688.com/page/creditdetail.htm"'
    get_name = re.findall(pattern_name, content)
    print(get_name)
    time.sleep(10)
    # 关闭浏览器
    await browser.close()
# 运行异步函数
resp=asyncio.get_event_loop().run_until_complete(main())
# 获取爬取后的商品信息
print(resp)
